/*
 * Joysticks.hpp
 *
 *  Created on: Feb 7, 2012
 *      Author: trwulff
 */

/*
 * Description:
 */
/*
1: A
2: B
3: X
4: Ya
5: Left Bumper
6: Right Bumper
7: Back
8: Start
9: Left Joystick
10: Right Joystick

The axis on the controller follow this mapping
(all output is between -1 and 1)

    1: Left Stick X Axis
    -Left:Negative ; Right: Positive
    2: Left Stick Y Axis
    -Up: Negative ; Down: Positive
    3: Triggers
    -Left: Positive ; Right: Negative
    4: Right Stick X Axis
    -Left: Negative ; Right: Positive
    5: Right Stick Y Axis
    -Up: Negative ; Down: Positive
    6: Directional Pad (Not recommended, buggy)
    7&8 individual joystick triggers?


Here is the mapping that I have found out as I have listed in the VI:

X Axis: Left Thumbstick Left-Right
X Axis Rotation: Right Thumbstick Left-Right
Y Axis: Left Thumb Stick (Needs to be negated or else up-down controlls are inverted)
Y Axis Rotation: Right Thumb Stick (Needs to be negated or else up-down controlls are inverted)
Z Axis (>0): Left Trigger
Z Axis (<0): Right Trigger

1: A Button
2: B Button
3: X Button
4: Y Button
5: Left Bumper
6: Right Bumper
7: Stop/Back Button
8: Start Button
9: Left Thumbstick Button
10: Right Thumbstick Button

DPAD:
-1: No Thumbpad Button
0: North Thumbpad Button
45: North-East Thumbpad Button
90: East Thumbpad Button
135: South-East Thumbpad Button
180: South Thumbpad Button
225: South-West Thumbpad Button
270: West Thumbpad Button
315: North-West Thumbpad Button
 * 
 */
//#include "Constants.hpp"
#include "WPILib.h"

#ifndef JOYSTICKS_HPP_
#define JOYSTICKS_HPP_
// class toggle
#define TOGGLE
#ifdef TOGGLE
class toggle
{
public:
	toggle(bool InitialState=0);
	~toggle();
	void Reset();
	void Set();
	void ModifyValue(bool &value);
private:
	bool Value;
	bool LastValue;
};
#endif
// example of operator overloading
//toggle::operator bool(){return Value;}
//void toggle::operator =(const bool other){Value=other;}
// end toggle

// SimpleDeadband class
/*
 * SimpleDeadband deletes a set of values between -band and band.
 * the output is scalled to eliminate a gap in the output. 
 * ie the output is zero within the band and linear from zero to one startinfg at the band edge.
 * 
 * 									Output Value 
 * 										| 1			   /
 * 										|			  /
 * 										|			 /
 * 										|			/
 * 										|		   /
 * 										|		  /
 * 										|	     /
 * 						________________|_______/__________ input value 
 * 						1		-band	|	   band		1
 * 								/		|
 * 							   /		|
 * 							  /			|
 * 							 /			|
 * 							/			|
 * 						   /		 	|
 * 						  / -1			|
 * 
 * 																								
 */
class SimpleDeadband
{
public:
	SimpleDeadband(float band=0.1);// set band upon initialization
	~SimpleDeadband();
	void Setband(float band=0.1);// set band
	void ModifyValue(float &value);
	float Getband();// get current band
private:
	float Band;// internal band
	float Value;
};

// end SimpleDeadband class

// XBox360 class

/*
 * This class maps the XBox axis, buttons,triggers and DPad to the names for easy refference
 */
class XBox360:public Joystick
{
public:
	/*
	 * Default constructor
	 */
         XBox360(UINT32 port);
           
	/*
	 * Default destructor
	 */
	  ~XBox360();
	  float GetLeftStickX();//Get X value for given axis
	  float GetLeftStickY();//Get Y value for given axis
	  float GetRightStickX();//Get X value for given axis
	  float GetRightStickY();//Get Y value for given axis
	  float GetDPad();//Get DPad value
	  float GetDPadX();//Get DPad X value (-1,0,1)
	  float GetDPadY();//Get DPad Y value (-1,0,1)
	  float GetTrigger();//Get Trigger value (-1,0,1)
	  bool GetLeftTrigger();// Get value for given button
	  bool GetRightTrigger();// Get value for given button
	  bool GetButtonA();// Get value for given button
	  bool GetButtonB();// Get value for given button
	  bool GetButtonX();// Get value for given button
	  bool GetButtonY();// Get value for given button
	  bool GetButtonLeftBumper();// Get value for given button
	  bool GetButtonRightBumper();// Get value for given button
	  bool GetButtonBack();// Get value for given button
	  bool GetButtonStart();// Get value for given button
	  bool GetButtonLeftStick();// Get value for given button
	  bool GetButtonRightStick();// Get value for given button
    	static const UINT32 kLeftStickX = 1;
      	static const UINT32 kLeftStickY = 2;
      	static const UINT32 kRightStickX = 4;
      	static const UINT32 kRightStickY = 5;
      	static const UINT32 kDpad = 6;
     	static const UINT32 kTrigger = 3;
     	static const UINT32 kButtonA = 1;
     	static const UINT32 kButtonB = 2;
     	static const UINT32 kButtonX = 3;
     	static const UINT32 kButtonY = 4;
     	static const UINT32 kButtonLeftBumper = 5;
     	static const UINT32 kButtonRightBumper = 6;
     	static const UINT32 kButtonBack = 7;
     	static const UINT32 kButtonStart = 8;
     	static const UINT32 kButtonLeftStick = 9;
     	static const UINT32 kButtonRightStick = 10;
  
protected:

private:
};


// Logitech Attack3 jystick

class Attack3:public Joystick
{
public:
	/*
	 * Default constructor
	 */
         Attack3(UINT32 port);
           
	/*
	 * Default destructor
	 */
	  ~Attack3();
	  float GetStickX();//Get X value for given axis
	  float GetStickY();//Get Y value for given axis
	  float GetThrottle();//Get X value for given axis
	  float GetRightStickY();//Get Y value for given axis
	  bool GetTrigger();//Get DPad Y value (-1,0,1)
	  bool GetLeftStickButton();// Get value for given button
	  bool GetMiddleStickButton();// Get value for given button
	  bool GetRightStickButton();// Get value for given button
	  bool GetRearStickButton();// Get value for given button
	  bool GetLeftFrontBaseButton();// Get value for given button
	  bool GetLeftRearBaseButton();// Get value for given button
	  bool GetRightFrontBaseButton();// Get value for given button
	  bool GetRightRearBaseButton();// Get value for given button
	  bool GetLeftBackButton();// Get value for given button
	  bool GetRightBackButton ();// Get value for given button
    	static const UINT32 kStickX = 1;
      	static const UINT32 kStickY = 2;
    	static const UINT32 kThrottle = 3;// note: this is assumed not known
     	static const UINT32 kTrigger = 1;
     	static const UINT32 kLeftStickButton = 4;
     	static const UINT32 kMiddleStickButton = 3;
     	static const UINT32 kRightStickButton = 5;
     	static const UINT32 kRearStickButton = 2;
     	static const UINT32 kLeftFrontBaseButton = 6;
     	static const UINT32 kLeftRearBaseButton = 7;
     	static const UINT32 kRightFrontBaseButton = 11;
     	static const UINT32 kRightRearBaseButton = 10;
    	static const UINT32 kLeftBackButton = 8;
    	static const UINT32 kRightBackButton = 9;
  
protected:

private:
};
// Logitech Attack3 jystick

#endif
//endif JOYSTICKS_HPP_
